<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script>
window.onload=function(){
	var spans=document.getElementsByTagName('span')[0];
	var texts=document.getElementsByTagName('textarea')[0];
	var int=30;
	texts.onkeydown=texts.onkeyup=function(){
		var val=this.value;
		var leng=val.length;
		if(leng>=int){
			leng=int;
			var newval=this.value.substr(0,30);
			this.value=newval;
		}
		spans.innerHTML='一共能输入'+int+'个，已经输入'+leng+'个，还剩'+(int-leng)+'个。'
			
	};
};
</script>
</head>

<body>
<span>一共能输入30个，已经输入0个，还剩30个。</span>
<textarea></textarea>
</body>
</html>
